package com.cby.android.library.base

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.cby.android.library.mvi.ApiError
import com.cby.android.library.mvi.PageStatus

abstract class BaseViewModel(application: Application) : AndroidViewModel(application) {

    /** 页面状态变化 */
    private val _pageStatus = MutableLiveData<PageStatus>()
    val pageStatus: LiveData<PageStatus>
        get() = _pageStatus

    /** 页面状态变化 - 加载中*/
    open fun showLoading() {
        _pageStatus.postValue(PageStatus.Loading)
    }

    /** 页面状态变化 - 显示内容*/
    open fun showContent() {
        _pageStatus.postValue(PageStatus.Success)
    }

    /** 页面状态变化 - 空*/
    open fun showEmpty() {
        _pageStatus.postValue(PageStatus.Empty)
    }

    /** 页面状态变化 - 错误 */
    open fun showError(errorMsg: String?) {
        _pageStatus.postValue(PageStatus.Error(ApiError(errorMsg)))
    }

}